import { useRef } from "react";

export default function Child(props) {
    const inputRef = useRef();
    const { setList } = props;
    // 将input框的值添加到父组件的list中
    const handle = () => {
        // setList([...list, inputRef.current.value]);
        setList(list => ([...list, inputRef.current.value]));
        // inputRef.current.value = "";
    }
    return (
        <div className="hd">
            <input type="text" ref={inputRef} />
            <button onClick={handle}>确认</button>
        </div>
    )
}
